<!--
 * @Description: 
 * @Author: charles
 * @Date: 2021-07-12 10:56:47
 * @LastEditors: Please set LastEditors
 * @LastEditTime: 2021-09-23 20:31:21
-->
<template>
  <div>
    <!-- 头部 -->
    <Header></Header>
    <!-- /头部 -->

    <!-- 体部 -->
    <div class="content">
      <div class="wrapper">
        <!-- {{}} -->
        <div class="title">
          {{ category.name }}
        </div>
        <div class="inner_content">
          <!-- 左侧表格 -->
          <div class="articleList">
            <!-- 文章列表 -->
            <ul v-if="categoryList.total > 0">
              <li
                class="list_list"
                v-for="item in categoryList.list"
                :key="item.id"
              >
                <div class="artitle" @click="todetails(item.id)">{{ item.title }}</div>
                <div class="list">
                  <!-- 发表时间 -->
                  <span>{{ item.publishTime | fmtDate }}</span>
                  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                  <!-- 阅读次数 -->
                  <span>{{ item.readTimes }}</span>
                </div>
              </li>
            </ul>
            <div v-else class="nodata">暂无数据</div>
            <!-- 分页 -->
            <div class="page">
              <el-pagination
                hide-on-single-page
                background
                layout="prev, pager, next"
                @current-change="handleCurrentChange"
                :page-size="categoryList.pageSize"
                :total="categoryList.total"
              >
              </el-pagination>
            </div>
          </div>
          <!-- 右侧表格 -->
          <div class="rank">
            <!--更新部分-->
            <div class="form">
              <div class="form--title">更新</div>
              <div class="kong"></div>
              <div
                class="substance"
                v-for="fr in data"
                :key="fr.id"
         
              >
                {{ fr.title }}
              </div>
            </div>
            <!--热门部分-->
            <div class="table">
              <div class="table--title">热门</div>
              <div class="kong1"></div>
              <div class="sub" v-for="tt in data" :key="tt.id">
                {{ tt.title }}
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
    <!-- /体部 -->

    <!-- 底部 -->
    <Footer></Footer>
    <!-- /底部 -->
  </div>
</template>

<script>
import {get} from '../utils/request'
import Header from "../components/Header";
import Footer from "../components/Footer";
export default {
  // 注册局部组件
  components: {
    Header,
    Footer
  },
  created() {
    this.category = this.$route.query;
    this.loadArticle();
  },
  // 监听器 监听$route.query
  watch:{
    '$route.query':{
      // 当属性发生变化触发handler函数
      handler(query){
        this.category=query;
        // 只有栏目不同展示数据不同
        this.loadArticle()
      },
      deep:true
    }
  },
  methods:{
    // 跳转到详情页
    todetails(id){
      this.$router.push({
        path:"/article",
        query:{id}
      })
    },
    // 给分页按钮绑定事件
    handleCurrentChange(page){
      // 代表当前点击的按钮
      // alert(page);  //2
      this.params.page=page; //2
      this.loadArticle();
    },
    // 加载文章方法
    loadArticle(){
       let url='/index/article/pageQuery';
       this.params.categoryId=this.category.id;
          // {
          //   page:1
          //   pageSize:5
          // }
        get(url,this.params).then(res=>{
          this.categoryList=res.data;  //{ list:[]}
        })
    }
  },
  data() {
    return {
      category: {},
      params:{
        page:1,
        pageSize:5
      },
      categoryList:{list:[]} 
    };
  }
};
</script>
<style lang="scss">
.content {
  padding: 2em 0.5em;
  background-color: #ecf6f2;
  // height: 500px;
  & > .wrapper {
    .inner_content {
      display: flex;
      flex-direction: row;
      flex-wrap: nowrap;
      & > div {
        background-color: #fff;
        height: 500px;
        padding: 1em 0.5em;
        border-radius: 5px;
      }
      .articleList {
        .artitle{
          cursor: pointer;
        }
        flex: 1;
        margin-right: 2em;
        ul > li.list_list {
          & > div {
            line-height: 2em;
            // padding: 1em .5em;
          }
          border-bottom: 1px solid #ededed;
        }
        .page {
          padding: 1em 0.5em;
          text-align: center;
        }
        .nodata {
          color: red;
          text-align: center;
          padding: 1em 0.5em;
        }
      }

      .title {
        font-size: 20px;
        font-weight: bold;
        color: rgb(29, 166, 186);
        padding: 1em 0.5em;
      }
      .rank {
        flex-basis: 200px;
        .form ,
        .table {
          height: 180px;
          position: relative;
          overflow: hidden;
          .kong,
          .kong1{height: 60px;}
          
        }
        .form {
          .form--title {
            font-size: 20px;
            font-weight: bold;
            background-color: #6b0202;
            color: rgb(29, 181, 186);
            padding: 1em 0.5em;
            position: absolute;
            top: 0;
            left: 0;
            margin-bottom: 10px;

          }
          .substance {
            position: static;
            margin-top: 1px;
            font-size: 0.9em;
            color: #000;
            padding: 1em 0.5em;
            text-align: center;
          }
          .substance:hover{
            color: #026b37;
            cursor: pointer;
          }
        }
        .table {
          .table--title {
            font-size: 20px;
            font-weight: bold;
            background-color: #6b0202;
            color: rgb(29, 162, 186);
            padding: 1em 0.5em;
            position: absolute;
            margin-bottom: 10px;
            left: 0;
          }
          .sub {
             position: static;
            margin-top: 1px;
            font-size: 0.9em;
            color: #000;
            padding: 1em 0.5em;
            text-align: center;
          }
          .sub:hover{
            color: #026b39;
            cursor: pointer;
          }
        }
      }
    }
  }
}
</style>